package com.example.home.government.acivity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.government.bean.PersonDetailsBean;
import com.example.home.tool.OKHttpTool;

import static com.example.home.tool.StaticActi.ip;

public class PersonDetails extends AppCompatActivity {
    private ImageView imgUrl;
    private TextView title;
    private TextView content;
    private TextView undertaker;
    private TextView createTime;
    private TextView state;
    private TextView detailResult;
    private String listId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_person_details);
        Intent intent = getIntent();
        listId = intent.getStringExtra("person");
        initView();
        getData();
    }

    private void getData() {
        OKHttpTool.doNetRequest("/prod-api/api/gov-service-hotline/appeal/"+listId,
                OKHttpTool.GET,
                PersonDetailsBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        PersonDetailsBean personDetailsBean = (PersonDetailsBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Glide.with(content).load(ip+personDetailsBean.getData().getImgUrl()).into(imgUrl);
                                title.setText(personDetailsBean.getData().getTitle());
                                content.setText(personDetailsBean.getData().getContent());
                                undertaker.setText(personDetailsBean.getData().getUndertaker());
                                createTime.setText(personDetailsBean.getData().getCreateTime());
                                detailResult.setText(personDetailsBean.getData().getDetailResult());
                                String sta = personDetailsBean.getData().getState();
                                if ("0".equals(sta)){
                                    state.setText("未处理");
                                }else if ("1".equals(sta)){
                                    state.setText("已处理");
                                }
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void initView() {
        imgUrl = findViewById(R.id.imgUrl);
        title = findViewById(R.id.title);
        content = findViewById(R.id.content);
        undertaker = findViewById(R.id.undertaker);
        createTime = findViewById(R.id.createTime);
        state = findViewById(R.id.state);
        detailResult = findViewById(R.id.detailResult);

    }
}